package com.fungo.baselib.utils

import android.os.Environment
import java.io.File

/**
 * sd卡存储
 */
class StorageUtil {

    private object StorageHolder {
        val holder = StorageUtil()
    }

    companion object {
        fun getInstance(): StorageUtil = StorageHolder.holder
    }

    var rootDir: File = File(Environment.getExternalStorageDirectory(), "xiaoming")

    init {
        if (!rootDir.exists()) rootDir.mkdir()
    }

    fun getPath(dirEnum: DirEnum): String {
        val path = File(rootDir, dirEnum.dir)
        if (!path.exists()) path.mkdir()
        return path.path
    }

    enum class DirEnum constructor(val dir: String) {

        images("Images"), avatars("Avatars"), apks("Apks"), files("files"), error("error"), cache("cache")
    }
}
